/**
 * <b>项目名：</b>hclv-web<br/>  
 * <b>包名：</b>com.flea.hclv.controller<br/>  
 * <b>文件名：</b>RoomStyleController.java<br/>  
 * <b>版本信息：</b>1.0<br/>  
 * <b>日期：</b>2018年9月18日 下午7:45:19<br/>  
 * <b>COPYRIGHT 2010-2012 ALL RIGHTS RESERVED 虫子科技</b>-版权所有<br/>
 */
package com.flea.hclv.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.flea.hclv.model.entity.HResourceRelation;
import com.flea.hclv.model.entity.HotelRoom;
import com.flea.hclv.service.HotelRoomService;
import com.flea.system.bean.FleaPage;
import com.flea.system.platform.session.FleaOrgUtils;
import com.flea.system.utils.ControllerResult;

/**
 * @description
 * @createTime 2018年9月18日 下午7:45:19
 * @modifyTime 
 * @author myflea@163.com
 * @version 1.0
 */
@Controller
@RequestMapping("/flea/hclv/hotel/hotelRoom")
public class HotelRoomController {
	@Autowired
	private HotelRoomService hotelRoomService;
	Logger logger = LoggerFactory.getLogger(HHotelController.class);

	@RequestMapping("saveOrUpdateRoom")
	public void saveOrUpdateHotel(HttpServletRequest request,
			HttpServletResponse response) {
		String hoteRoomlJSON = request.getParameter("model");
		
		String resource = request.getParameter("files");
		List<HResourceRelation> filesRelation = JSON.parseArray(resource, HResourceRelation.class);

		String userId = FleaOrgUtils.getCurUserUuid(request);
		HotelRoom room = JSON.parseObject(hoteRoomlJSON, HotelRoom.class);
	

		boolean result = hotelRoomService.saveOrUpdate(room, filesRelation, userId);

		ControllerResult cResult = new ControllerResult(result, "操作成功", result);
		cResult.WriteToPage(response);
	
	}
	@RequestMapping("/queryAllForPage")
	public void queryAll(HttpServletRequest request, FleaPage<HotelRoom> paging,
			HttpServletResponse response) {

		String queryName = request.getParameter("queryName");
		String queryLevel = request.getParameter("queryLevel");
		String queryProvince = request.getParameter("queryProvince");
		String queryCity = request.getParameter("queryCity");
		String queryZone = request.getParameter("queryZone");
		String queryStyleType = request.getParameter("queryStyle");
		String userUuid = FleaOrgUtils.getCurUserUuid(request);
		FleaPage<HotelRoom> pageList = hotelRoomService.findForGird(queryName,
				queryLevel, queryProvince, queryCity, queryZone,queryStyleType,
				paging.getCurPage(), paging.getPageSize(),userUuid);

		ControllerResult conresult = new ControllerResult(pageList);
		conresult.set(true, "操作成功");

		conresult.WritePagingDataToPage(response, pageList);

	}
	@RequestMapping("/deletByIds")
	public void deletHotel(HttpServletRequest request,
			@Param("ids") String ids, HttpServletResponse response) {

		String userId = FleaOrgUtils.getCurUserUuid(request);
		boolean result = hotelRoomService.deleteByIds(ids, userId);

		ControllerResult cResult = new ControllerResult(result,
				result == true ? "操作成功" : "操作失败", result);
		cResult.WriteToPage(response);
	}

}
